package com.example.texted.guava;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.primitives.Ints;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringJoiner;

/**
 * <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
 * <dependency>
 *     <groupId>com.google.guava</groupId>
 *     <artifactId>guava</artifactId>
 *     <version>30.1-jre</version>
 * </dependency>
 */
public class Do {
    public static void main(String[] args) {
        ArrayList<Integer> strings = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            strings.add(i);
        }
        StringJoiner stringJoiner = new StringJoiner(",");
        stringJoiner.add("1");
        stringJoiner.add("2");
        stringJoiner.add("3");
        stringJoiner.add("4");
        System.out.println(stringJoiner.toString());
        Joiner joiner = Joiner.on(',');
        long now = System.currentTimeMillis();
        String join = joiner.skipNulls().join(strings);
        long end = System.currentTimeMillis();
        System.out.println(join);
        System.out.println("time: " + (end - now));

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("张三","老板");
        hashMap.put("李四","普通员工");
        Joiner joiner1 = Joiner.on("\r\n");
        String join1 = joiner1.withKeyValueSeparator("是：").join(hashMap);
        System.out.println(join1);

        String s = "你好，Guava！";
        Iterable<String> split = Splitter.on("，").split(s);
        split.forEach(System.out::println);
        Iterable<String> split2 = Splitter.fixedLength(2).split(s);
        split2.forEach(System.out::println);
        boolean i = false;
        System.out.println(Ints.max(Ints.toArray(strings)));
    }
}
